#include "kernel.h"

void shell_init(void){
    //while(1)
    {

        uint32_t ret=InitUART(115200,NULL);
        
        if (ret != WIFI_IOT_SUCCESS)
        {
            printf("Failed to init uart! Err code = %d\n", ret);
            return;
        }

        char* str=(char*)malloc(128);
        *str=0;

        while (1)
        {
            uint8_t *in=ScanfUART();
            strcat(str,(char*)in);
            printf("TTY INPUT CACHE:");
            PrintfUART((char*)str);
            printf("\r\n");
            if(str[strlen(str)-1]==0x0D){   
                str[strlen(str-1)]=0;       

                char* cmdline=malloc(strlen(str));                
                strcpy(cmdline,str);

                //DO SHELL THINGS HERE
                printf("CMDLINE INPUT:");
                printf(cmdline);
                printf("\r\n");
                //DO SHELL THINGS HERE END
               
                str-=strlen(cmdline);
                free(cmdline);
                free(str);
                str=(char*)malloc(128);
                *str=0;

            }
            usleep(1000000);
        }
    }
}